package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.wemedia.WmUserControllerApi;
import com.heima.model.media.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 96558
 * @Date 2021/1/11 23:02
 * @Version 1.0
 **/
@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {
    /**
     * 保存自媒体用户
     *
     * @param wmUser
     * @return wmUser 需要主键返回
     */

    @Autowired
    private WmUserService wmUserService;

    @PostMapping("/save")
    @Override
    public WmUser save(@RequestBody WmUser wmUser) {
        wmUserService.save(wmUser);
        return wmUser;
    }

    @GetMapping("/findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable("name") String name) {
        return wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
    }
}
